object demo03 {
  def main(args: Array[String]): Unit = {
    println(fbn(3))
    println(commonFbn(3))
    println(myDate(5))
    printString("123", "565", "562")
    for (i <- 1 to 10) {
      println(i + "的阶乘是：" + myMain(i))
    }
    println(sumInt(10, 6))
    println(sumInt())
    produt("asd")
  }

  //
  def produt(s: String): Unit = {
    var num: Long = 1
    s.foreach(char => {
      num *= char.toLong
    })
    println(num)
  }

  //内嵌函数
  def myFac(a: Int): Int = {
    def fact(a: Int, b: Int): Int = {
      if (a <= 1) b
      else {
        println("输出我的内嵌函数循环：" + a)
        fact(a - 1, a * b)
      }
    }

    fact(a, 1)
  }

  //  整数相加
  def sumInt(a: Int = 5, b: Int = 7): Int = {
    var sum: Int = 0
    sum = a + b
    return sum
  }

  //阶乘
  def myMain(n: Int): Int = {
    if (n <= 1) 1
    else {
      println("我的函数递归值：" + n)
      myMain(n - 1) * n
    }
  }

  //  hello scala
  def printMe(): Unit = {
    println("Hello,Scala!")
  }

  //  获取系统时间
  def time(): Long = {
    println("获取时间，单位是纳米")
    System.nanoTime()
  }

  //获取我的时间
  def myDate(sh: => Long): Long = {
    var myTime: Long = sh
    myTime
  }

  //相同类型多次传值
  def printString(args: String*): Unit = {
    var i: Int = 0
    for (arg <- args) {
      println("第" + i + "项：" + arg)
      i += 1
    }
  }

  //斐波那契常规
  def commonFbn(n: Int): Int = {
    if (n == 0) return 0
    if (n == 1) return 1
    var p = 0
    var q = 1
    //    i是项数
    var i = 1
    while (i < n) {
      val tmp = p
      p = q
      q = tmp + p
      i += 1
    }
    return q
  }

  //  斐波那契递归
  def fbn(n: Int): Int = {
    if (n == 1 || n == 2) 1
    else fbn(n - 1) + fbn(n - 2)
  }
}
